<?php

/**
 * Radcodes - SocialEngine Module
 *
 * @category   Application_Extensions
 * @package    Page
 * @copyright  Copyright (c) 2009-2010 Radcodes LLC (http://www.radcodes.com)
 * @license    http://www.radcodes.com/license/
 * @version    $Id$
 * @author     Vincent Van <vincent@radcodes.com>
 */

class Cmspage_Form_Admin_Level extends Authorization_Form_Admin_Level_Abstract {
	
	public function init() {
		parent::init ();
		
		$this->setTitle ( 'Member Level Settings' )->setDescription ( "CMSPAGE_FORM_ADMIN_LEVEL_DESCRIPTION" );
		
		$this->addElement ( 'Radio', 'view', array ('label' => 'Allow Viewing of Pages?', 'description' => 'CMSPAGE_FORM_ADMIN_LEVEL_VIEW_DESCRIPTION', 'multiOptions' => array (2 => 'Yes, allow viewing of all pages, even private ones.', 1 => 'Yes, allow viewing of pages.', 0 => 'No, do not allow pages to be viewed.' ), 'value' => ($this->isModerator () ? 2 : 1) ) );
		if (! $this->isModerator ()) {
			unset ( $this->view->options [2] );
		}
		
		if (! $this->isPublic ()) {
			
			$this->addElement ( 'Radio', 'create', array ('label' => 'Allow Creation of Pages?', 'description' => 'CMSPAGE_FORM_ADMIN_LEVEL_CREATE_DESCRIPTION', 'multiOptions' => array (1 => 'Yes, allow creation of pages.', 0 => 'No, do not allow pages to be created.' ), 'value' => 1 ) );
			
			$this->addElement ( 'Radio', 'edit', array ('label' => 'Allow Editing of Pages?', 'description' => 'CMSPAGE_FORM_ADMIN_LEVEL_EDIT_DESCRIPTION', 'multiOptions' => array (2 => 'Yes, allow members to edit all pages.', 1 => 'Yes, allow members to edit their own pages.', 0 => 'No, do not allow members to edit their pages.' ), 'value' => ($this->isModerator () ? 2 : 1) ) );
			if (! $this->isModerator ()) {
				unset ( $this->edit->options [2] );
			}
			
			$this->addElement ( 'Radio', 'delete', array ('label' => 'Allow Deletion of Pages?', 'description' => 'CMSPAGE_FORM_ADMIN_LEVEL_DELETE_DESCRIPTION', 'multiOptions' => array (2 => 'Yes, allow members to delete all pages.', 1 => 'Yes, allow members to delete their own pages.', 0 => 'No, do not allow members to delete their pages.' ), 'value' => ($this->isModerator () ? 2 : 1) ) );
			if (! $this->isModerator ()) {
				unset ( $this->delete->options [2] );
			}
			
			// Element: comment
			$this->addElement ( 'Radio', 'comment', array ('label' => 'Allow Commenting on Pages?', 'description' => 'CMSPAGE_FORM_ADMIN_LEVEL_COMMENT_DESCRIPTION', 'multiOptions' => array (2 => 'Yes, allow members to comment on all pages, including private ones.', 1 => 'Yes, allow members to comment on pages.', 0 => 'No, do not allow members to comment on pages.' ), 'value' => ($this->isModerator () ? 2 : 1) ) );
			if (! $this->isModerator ()) {
				unset ( $this->comment->options [2] );
			}
			
			// Element: photo
			$this->addElement ( 'Radio', 'photo', array ('label' => 'Allow Uploading of Photos?', 'description' => 'CMSPAGE_FORM_ADMIN_LEVEL_PHOTO_DESCRIPTION', 'multiOptions' => array (2 => 'Yes, allow photo uploading to all pages, including private ones.', 1 => 'Yes, allow photo uploading to pages.', 0 => 'No, do not allow photo uploading.' ), 'value' => ($this->isModerator () ? 2 : 1) ) );
			if (! $this->isModerator ()) {
				unset ( $this->photo->options [2] );
			}
			
			$this->addElement ( 'Radio', 'script', array ('label' => 'Allow Custom Script?', 'description' => 'CMSPAGE_FORM_ADMIN_LEVEL_SCRIPT_DESCRIPTION', 'multiOptions' => array (1 => 'Yes, allow input custom javascript on pages.', 0 => 'No, do not allow input custom javascript.' ), 'value' => ($this->isModerator () ? 1 : 0) ) );
			
			$this->addElement ( 'Radio', 'style', array ('label' => 'Allow Custom Style?', 'description' => 'CMSPAGE_FORM_ADMIN_LEVEL_STYLE_DESCRIPTION', 'multiOptions' => array (1 => 'Yes, allow input custom css on pages.', 0 => 'No, do not allow input custom css.' ), 'value' => ($this->isModerator () ? 1 : 0) ) );
			
			$this->addElement ( 'Radio', 'featured', array ('label' => 'Mark as Featured on Creation?', 'description' => 'CMSPAGE_FORM_ADMIN_LEVEL_FEATURED_DESCRIPTION', 'multiOptions' => array (1 => 'Yes, mark cmspage as Featured when created.', 0 => 'No, do not mark cmspage as Featured when created.' ), 'value' => 0 ) );
			
			$this->addElement ( 'Radio', 'sticky', array ('label' => 'Mark as Sticky on Creation?', 'description' => 'CMSPAGE_FORM_ADMIN_LEVEL_STICKY_DESCRIPTION', 'multiOptions' => array (1 => 'Yes, mark page as Sticky when created.', 0 => 'No, do not mark page as Sticky when created.' ), 'value' => 0 ) );
			
			// PRIVACY ELEMENTS
			$this->addElement ( 'MultiCheckbox', 'auth_view', array ('label' => 'Pages Page Privacy', 'description' => 'CMSPAGE_FORM_ADMIN_LEVEL_AUTHVIEW_DESCRIPTION', 'multiOptions' => array ('everyone' => 'Everyone', 'registered' => 'Registered Members', 'owner_network' => 'Friends and Networks', 'owner_member_member' => 'Friends of Friends', 'owner_member' => 'Friends Only', 'owner' => 'Just Me' ), 'value' => array ('everyone', 'registered', 'owner_network', 'owner_member_member', 'owner_member', 'owner' ) ) );
			
			$this->addElement ( 'MultiCheckbox', 'auth_comment', array ('label' => 'Page Comment Options', 'description' => 'CMSPAGE_FORM_ADMIN_LEVEL_AUTHCOMMENT_DESCRIPTION', 'description' => '', 'multiOptions' => array ('registered' => 'Registered Members', 'owner_network' => 'Friends and Networks', 'owner_member_member' => 'Friends of Friends', 'owner_member' => 'Friends Only', 'owner' => 'Just Me' ), 'value' => array ('registered', 'owner_network', 'owner_member_member', 'owner_member', 'owner' ) ) );
			
			$this->addElement ( 'Text', 'auth_html', array ('label' => 'HTML in Pages?', 'description' => 'CMSPAGE_FORM_ADMIN_LEVEL_HTML_DESCRIPTION', 'value' => 'strong, b, em, i, u, strike, sub, sup, p, div, pre, address, h1, h2, h3, h4, h5, h6, span, ol, li, ul, a, img, embed, br, hr' ) );
			
			// Element: auth_htmlattrs
			$this->addElement ( 'Text', 'auth_htmlattrs', array ('label' => 'HTML Attributes in WYSIWYG Editor', 'description' => 'CMSPAGE_FORM_ADMIN_LEVEL_HTMLATTRS_DESCRIPTION', 'class' => 'long', 'value' => 'href, src, alt, border, align, width, height, vspace, hspace, target, style, name, value, id, title, class, colspan, type, allowscriptaccess, allowfullscreen, rows, cols, size, language' ) );
			
			$this->addElement ( 'Text', 'max', array ('label' => 'Maximum Allowed Pages', 'description' => 'CMSPAGE_FORM_ADMIN_LEVEL_MAXNUM_DESCRIPTION', 'class' => 'short' ) );
		
		} // end isPublic()
	}
	
	public function initAEMP() {
		
		$this->addElement ( 'Radio', 'script', array ('label' => 'Allow Custom Script?', 'description' => 'CMSPAGE_FORM_ADMIN_LEVEL_SCRIPT_DESCRIPTION', 'multiOptions' => array (1 => 'Yes, allow input custom javascript on pages.', 0 => 'No, do not allow input custom javascript.' ), 'value' => 0 ) );
		
		$this->addElement ( 'Radio', 'style', array ('label' => 'Allow Custom Style?', 'description' => 'CMSPAGE_FORM_ADMIN_LEVEL_STYLE_DESCRIPTION', 'multiOptions' => array (1 => 'Yes, allow input custom css on pages.', 0 => 'No, do not allow input custom css.' ), 'value' => 0 ) );
		
		$this->addElement ( 'Button', 'submit', array ('label' => 'Save Settings', 'type' => 'submit' ) );
	
	}
	
	public function initBAK() {
		$this->setTitle ( 'Member Level Settings' )->setDescription ( "CMSPAGE_FORM_ADMIN_LEVEL_DESCRIPTION" );
		
		$this->loadDefaultDecorators ();
		$this->getDecorator ( 'Description' )->setOptions ( array ('tag' => 'h4', 'placement' => 'PREPEND' ) );
		
		// prepare user levels
		$table = Engine_Api::_ ()->getDbtable ( 'levels', 'authorization' );
		$select = $table->select ();
		$user_levels = $table->fetchAll ( $select );
		
		foreach ( $user_levels as $user_level ) {
			$levels_prepared [$user_level->level_id] = $user_level->getTitle ();
		}
		
		// category field
		$this->addElement ( 'Select', 'level_id', array ('label' => 'Member Level', 'multiOptions' => $levels_prepared, 'onchange' => 'javascript:fetchLevelSettings(this.value);' ) );
		
		$this->addElement ( 'Radio', 'view', array ('label' => 'Allow Viewing of Pages?', 'description' => 'CMSPAGE_FORM_ADMIN_LEVEL_VIEW_DESCRIPTION', 'multiOptions' => array (0 => 'No, do not allow pages to be viewed.', 1 => 'Yes, allow viewing of pages.', 2 => 'Yes, allow viewing of all pages, even private ones.' ), 'value' => 1 ) );
		
		$this->addElement ( 'Radio', 'create', array ('label' => 'Allow Creation of Pages?', 'description' => 'CMSPAGE_FORM_ADMIN_LEVEL_CREATE_DESCRIPTION', 'multiOptions' => array (1 => 'Yes, allow creation of pages.', 0 => 'No, do not allow pages to be created.' ), 'value' => 1 ) );
		
		$this->addElement ( 'Radio', 'edit', array ('label' => 'Allow Editing of Pages?', 'description' => 'CMSPAGE_FORM_ADMIN_LEVEL_EDIT_DESCRIPTION', 'multiOptions' => array (0 => 'No, do not allow members to edit their pages.', 1 => 'Yes, allow members to edit their own pages.', 2 => 'Yes, allow members to edit all pages.' ), 'value' => 1 ) );
		
		$this->addElement ( 'Radio', 'delete', array ('label' => 'Allow Deletion of Pages?', 'description' => 'CMSPAGE_FORM_ADMIN_LEVEL_DELETE_DESCRIPTION', 'multiOptions' => array (0 => 'No, do not allow members to delete their pages.', 1 => 'Yes, allow members to delete their own pages.', 2 => 'Yes, allow members to delete all pages.' ), 'value' => 1 ) );
		
		$this->addElement ( 'Radio', 'photo', array ('label' => 'Allow Uploading of Photos?', 'description' => 'CMSPAGE_FORM_ADMIN_LEVEL_PHOTO_DESCRIPTION', 'multiOptions' => array (1 => 'Yes, allow photo uploading to pages.', 0 => 'No, do not allow photo uploading.' ), 'value' => 1 ) );
		
		$this->addElement ( 'Radio', 'script', array ('label' => 'Allow Custom Script?', 'description' => 'CMSPAGE_FORM_ADMIN_LEVEL_SCRIPT_DESCRIPTION', 'multiOptions' => array (1 => 'Yes, allow input custom javascript on pages.', 0 => 'No, do not allow input custom javascript.' ), 'value' => 0 ) );
		
		$this->addElement ( 'Radio', 'style', array ('label' => 'Allow Custom Style?', 'description' => 'CMSPAGE_FORM_ADMIN_LEVEL_STYLE_DESCRIPTION', 'multiOptions' => array (1 => 'Yes, allow input custom css on pages.', 0 => 'No, do not allow input custom css.' ), 'value' => 0 ) );
		
		$this->addElement ( 'Radio', 'featured', array ('label' => 'Mark as Featured on Creation?', 'description' => 'CMSPAGE_FORM_ADMIN_LEVEL_FEATURED_DESCRIPTION', 'multiOptions' => array (1 => 'Yes, mark page as Featured when created.', 0 => 'No, do not mark page as Featured when created.' ), 'value' => 0 ) );
		
		$this->addElement ( 'Radio', 'sticky', array ('label' => 'Mark as Sticky on Creation?', 'description' => 'CMSPAGE_FORM_ADMIN_LEVEL_SPONSORED_DESCRIPTION', 'multiOptions' => array (1 => 'Yes, mark page as Sticky when created.', 0 => 'No, do not mark page as Sticky when created.' ), 'value' => 0 ) );
		
		// PRIVACY ELEMENTS
		$this->addElement ( 'MultiCheckbox', 'auth_view', array ('label' => 'Pages Page Privacy', 'description' => 'CMSPAGE_FORM_ADMIN_LEVEL_AUTHVIEW_DESCRIPTION', 'multiOptions' => array ('everyone' => 'Everyone', 'owner_network' => 'Friends and Networks', 'owner_member_member' => 'Friends of Friends', 'owner_member' => 'Friends Only', 'owner' => 'Just Me' ), 'value' => array ('everyone', 'owner_network', 'owner_member_member', 'owner_member', 'owner' ) ) );
		
		$this->addElement ( 'MultiCheckbox', 'auth_comment', array ('label' => 'Page Comment Options', 'description' => 'CMSPAGE_FORM_ADMIN_LEVEL_AUTHCOMMENT_DESCRIPTION', 'description' => '', 'multiOptions' => array ('everyone' => 'Everyone', 'owner_network' => 'Friends and Networks', 'owner_member_member' => 'Friends of Friends', 'owner_member' => 'Friends Only', 'owner' => 'Just Me' ), 'value' => array ('everyone', 'owner_network', 'owner_member_member', 'owner_member', 'owner' ) ) );
		
		$this->addElement ( 'Text', 'max', array ('label' => 'Maximum Allowed Pages', 'description' => 'CMSPAGE_FORM_ADMIN_LEVEL_MAXNUM_DESCRIPTION', 'class' => 'short' ) );
		
		$this->addElement ( 'Text', 'auth_html', array ('label' => 'HTML in Pages?', 'description' => 'CMSPAGE_FORM_ADMIN_LEVEL_HTML_DESCRIPTION', 'value' => 'strong, b, em, i, u, strike, sub, sup, p, div, pre, address, h1, h2, h3, h4, h5, h6, span, ol, li, ul, a, img, embed, br, hr' ) );
		
		$this->addElement ( 'Button', 'submit', array ('label' => 'Save Settings', 'type' => 'submit' ) );
	
	}
}